<template>
<van-datetime-picker
  v-model="currentDate"
  type="date"
  title="选择年月日"
  :min-date="minDate"
  :max-date="maxDate"
  @cancel="$emit('close')"
  @confirm="onConfirm"
/>
</template>

<script>
import { updateUserName } from '@/api/user'
import dayJs from 'dayjs'
export default {
  components: {},
  props: {
    value: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      minDate: new Date(1970, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.value)
    }
  },
  computed: {},
  watch: {},
  created () {
  },
  mounted () {},
  methods: {
    async onConfirm () {
      try {
        await updateUserName({
          birthday: dayJs(this.currentDate).format('YYYY-MM-DD')
        })
        this.$emit('input', dayJs(this.currentDate).format('YYYY-MM-DD'))
        this.$emit('close')
        this.$toast('更新成功')
      } catch (err) {
        console.log(err)
      }
    }
  }
}
</script>

<style scoped>

</style>
